// 首页
<template>
    <div>
        <component :is="componentName"></component>
    </div>
</template>

<script>
import home from './home.vue'
import bind from './bindUnit/index.vue'
import bindCreate from './bindUnit/create.vue'
export default {
    components: {
        home,
        bind,
        bindCreate,
    },
    data() {
        return {
            loading: false,
            componentName: '',
        }
    },
    mounted() {
        this.goToHomePage()
        window.localStorage.removeItem('deviceActiveStep')
    },
    methods: {
        goToHomePage() {
            let self = this
            self.$util
                .request(
                    '/app/ent/entPersonBase/getPersonBaseByCurrentUser',
                    {},
                    'post'
                )
                .then((res) => {
                    if (res.data.parameters) {
                        if (res.data.parameters.isPerson != 1) {
                            self.componentName = 'home'
                        } else {
                            let status = res.data.parameters.status
                            if (status == 1) {
                                self.componentName = 'home'
                            } else if (status == 3) {
                                self.componentName = 'bind'
                            } else if (status == 2) {
                                let caseId = null
                                if (
                                    res.data.parameters &&
                                    res.data.parameters.entPerson
                                ) {
                                    caseId =
                                        res.data.parameters.entPerson.caseId
                                }
                                if (
                                    res.data.parameters &&
                                    res.data.parameters.entPersonCase
                                ) {
                                    caseId =
                                        res.data.parameters.entPersonCase.caseId
                                }
                                if (caseId) {
                                    self.$framework.util
                                        .getPromise(
                                            `/app/workflow/getWorkflowArgs`,
                                            { formId: caseId }
                                        )
                                        .then((rlt) => {
                                            let url = ''
                                            rlt.appUrl =
                                                '/business/qzjx/bindUnit/create'
                                            if (rlt.taskId) {
                                                url = `${
                                                    rlt.appUrl
                                                }?action=processEdit&taskId=${
                                                    rlt.taskId
                                                }&assigneeId=${
                                                    rlt.assigneeId
                                                }&appCode=${
                                                    rlt.appCode
                                                }&version=${
                                                    rlt.version
                                                }&_r=${new Date().getTime()}`
                                            } else if (rlt.historyTaskId) {
                                                url = `${
                                                    rlt.appUrl
                                                }?action=processView&historyTaskId=${
                                                    rlt.historyTaskId
                                                }&appCode=${
                                                    rlt.appCode
                                                }&version=${
                                                    rlt.version
                                                }&_r=${new Date().getTime()}&assigneeId=${
                                                    rlt.assigneeId
                                                }`
                                            } else {
                                                self.$toast(
                                                    '无法获取应用的处理地址！'
                                                )
                                            }
                                            if (url) {
                                                setTimeout(() => {
                                                    self.$f7router.navigate(url)
                                                }, 500)
                                            }
                                        })
                                } else {
                                    self.$toast('数据获取失败！')
                                }
                            }
                        }
                    }
                })
        },
    },
}
</script>

<style lang="less" scoped></style>
